<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<title>componentReceiveProps</title>
	<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
	<script src="https://market-cowen.top/static/17.0.1/react.development.js"></script>
	<script src="https://market-cowen.top/static/17.0.1/react-dom.development.js"></script>
	<script src="https://market-cowen.top/static/17.0.1/babel.min.js"></script>
	<style>
		.parent{
			padding: 60px;
			background:#ddd; 
		}
		.child{
			padding: 30px;
			background:green; 
		}
	</style>
</head>
<body>
	<div class="container">
		<div id="app"></div>
	</div>
</body>
</html>
<script type="text/babel">
	class Child extends React.Component{
		UNSAFE_componentWillReceiveProps(){
			console.log('componentWillReceiveProps')
		}
		UNSAFE_componentWillUpdate(){
			console.log('componentWillUpdate')
		}
		componentDidUpdate(){
			console.log('componentDidUpdate')
		}
		render(){
			console.log('render')
			return(
				<div className="child">
					<h3>这里是子组件{this.props.title}</h3>
				</div>
			)
		}
	}
	class Parent extends React.Component{
		state={title:'初始标题'}
		updateTitle=()=>{
			this.setState({title:new Date().getTime()})
		}
		render(){
			return(
				<div className="parent">
					<h2>这里是父组件</h2>
					<button onClick={this.updateTitle} className="mb-3 btn btn-primary">更改标题</button>
					<Child title={this.state.title} />
				</div>
			)
		}
	}

	ReactDOM.render(<Parent/>,document.getElementById('app'))
</script>